<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>编辑</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
</head>
<body>
<div class="page-content-wrap">
    <form class="layui-form">
        <div class="layui-tab" style="margin:0 50px 70px 30px;">
            <div class="layui-tab-content">
                <div class="layui-tab-item"></div>
                <div class="layui-tab-item layui-show">
                    <input type="hidden" class="form-control id" id="id" name="id" value="${sysRule.id}" />
                    <input type="hidden" class="form-control parentId" id="parentId" name="parentId" value="${sysRule.parentId}" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级：</label>
                        <div class="layui-input-block">
                            <input type="text" name="parentName" placeholder="" readonly value="${sysRule.parentName!'无'}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;类型：</label>
                        <div class="layui-input-block">
                            <select name="type" lay-filter="type" id="type">

                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入名称" value="${sysRule.name}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item typeSelect">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;条件语句：</label>
                        <div class="layui-input-block">
                            <input type="text" name="sqlContent" id="sqlContent"  placeholder="请输入条件语句" value="${sysRule.sqlContent}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item typeSelect">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;标识符：</label>
                        <div class="layui-input-block">
                            <input type="text" name="permission" id="permission" placeholder="请输入标识符" value="${sysRule.permission}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;排序：</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" id="sort"  placeholder="请输入排序" value="${sysRule.sort}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <div class="">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>

<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery', 'page','dialog','baseutil'], function() {
        var form = layui.form,
            $ = layui.jquery,
            page = layui.page,
            baseutil = layui.baseutil,
            dialog = layui.dialog;
        page.initDict("rule_type",function (dictData) {
            page.showDict($("#type"),page.aceeptDictContentList(dictData,"rule_type"),"",'${sysRule.type}');
        });
        if('${sysRule.type}'=="1"){
            $(".typeSelect").hide();
        }
        //监听下拉框
        form.on('select(type)', function(data){
            //1、目录，2、规则
            if("2"==data.value){
                $(".typeSelect").show();
            }else{
                $(".typeSelect").hide();
            }
        });
        //监听提交
        form.on('submit(submitBtn)', function(data){
            var type=$("#type").val();
            var name=$("#name").val();
            if(name == null || name == ""){
                dialog.msg("请输入名称");
                return false;
            }
            //1、目录，2、规则
            if("2"==type) {
                var sqlContent = $("#sqlContent").val();
                if (sqlContent == null || sqlContent == "") {
                    dialog.msg("请输入条件语句");
                    return false;
                }
            }
            var sort=$("#sort").val();
            if(sort == null || sort == ""){
                dialog.msg("请输入排序");
                return false;
            }
            baseutil.post("/sysRule/addOrUpdate",data.field,function (result) {
                if(result.code==0){
                    $("#save").click();
                }else{
                    dialog.msg(result.msg);
                }
            });
            return false;
        });
    });
</script>
</body>

</html>